console.log('---------------------------------------217------------------------------------------')
// 1
var obj1 = {
    name: 'Brave'
}

// 2
function person(name, age) {
    this.name = name;
    this.age = age
}
var son = new person('123', 123)

// 3
var Dog = new Object()
Dog.name = '132';
Dog.age = 18;

// 4
function Cat() {

}
Cat.prototype.name = "d"
var cat = new Cat()


// 1
function num1() {

}
// 2
var num2 = () => { }

// 3
var num3 = new Function('num1', 'num2', 'return num1+num2')


// 1
var str = '123AJNS???'
console.log(str.length)
for (var i = 0; i < str.length; i++) {
    console.log(typeof str.charAt(i))
}
var str1 = str.split('')
console.log(str1)
console.log(str1[0])
console.log(typeof str1[0])
console.log(JSON.parse(str1[0]))
console.log(typeof JSON.parse(str1[0]))

// 2浅拷贝，深拷贝
var shallowCopy = function (obj) {
    // 只拷贝对象
    if (typeof obj !== 'object') return;
    // 根据obj的类型判断是新建一个数组还是一个对象
    var newObj = obj instanceof Array ? [] : {};
    // 遍历obj,并且判断是obj的属性才拷贝
    for (var key in obj) {
        if (obj.hasOwnProperty(key)) {
            newObj[key] = obj[key];
        }
    }
    return newObj;
}

var deepCopy = function (obj) {
    // 只拷贝对象
    if (typeof obj !== 'object') return;
    // 根据obj的类型判断是新建一个数组还是一个对象
    var newObj = obj instanceof Array ? [] : {};
    for (var key in obj) {
        // 遍历obj,并且判断是obj的属性才拷贝
        if (obj.hasOwnProperty(key)) {
            // 判断属性值的类型，如果是对象递归调用深拷贝
            newObj[key] = typeof obj[key] === 'object' ? deepCopy(obj[key]) : obj[key];
        }
    }
    return newObj;
}


function shallCopy(obj) {
    if (typeof obj !== 'object') return
    var newObj = obj instanceof Array ? [] : {}
    for (key in obj) {
        if (obj.hasOwnProperty(key)) {
            newObj[key] = obj[key]
        }
    }
    return newObj
}

function deepCopy(obj) {
    if (typeof obj !== 'object') return
    var newObj = obj instanceof Array ? [] : {}
    for (key in obj) {
        if (obj.hasOwnProperty(key)) {
            newObj[key] = typeof obj[key] == 'object' ? deepCopy(obj[key]) : obj[key]
        }
    }
    return newObj
}

var o = {
    name: '胖鸡',
    age: 18,
    sex: '男',
    love: {
        game: 'cf',
        music: 'flowerDance'
    }
}
var o1 = shallCopy(o)
var o2 = deepCopy(o)
console.log(o1)
console.log(o2)
o.love.game = 'lol'
console.log(o1)
console.log(o2)